import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

ParaCalSubItem{
    id: root
    title: qsTr("参数设置")
    width: 784
    height: 338
    property color btnColor: "#7080C0"
    property int btnHeight: 50
    property int btnWidth: 125
    signal startLoad
    onSignalPre: {
    }
    onSignalNext: {
    }
    onSignalOK: {
        if(paraCalLoader.visible===true){
            return
        }
        //normalSettingSaveOK=false;
        paraCalLoader.visible=true
        var result =
        mymodbus.setUnit(unit.currentValue)
        && mymodbus.setAxisCount(axisCount.currentValue);
        paraCalLoader.visible=false
        if(result){
            //normalSettingSaveOK=true;

            paraCalView.signalSuccess()
            //normalParaSaveOKDialog.open()
//            normalParaSaveOKDialog.accepted.connect(function() {
//                                    normalParaSaveOKDialog.close()
//                                })
        }
        else
        {
            paraCalView.signalFailed()
//            normalParaSaveOKDialog.open()
//            normalParaSaveOKDialog.accepted.connect(function() {
//                                    normalParaSaveOKDialog.close();
//                                })
        }
    }
    onStartLoad: {
        //paraCalLoader.visible=true
        //unit.currentIndex = unit.find(mymodbus.unit)
        //mymodbus.getDecimalPlaces()
        //mymodbus.getMinGraduation()
        unit.currentIndex=unit.find(mymodbus.unit)
        axisCount.currentIndex=axisCount.find(mymodbus.axisCount)
        //mymodbus.decimalPlacesChanged.connect(onDecimalPlacesChanged);
        //mymodbus.minGraduationChanged.connect(onMinGraduationChanged);
    }
    Component.onCompleted: {
        startLoad()

    }
    GridLayout{
                    id: normalSettingsLayout
                    rows: 1
                    columns: 4
                    anchors.centerIn: parent
                    rowSpacing: 40
                        Button
                        {
                            Layout.row:1
                            Layout.column:0
                            Layout.preferredWidth: btnWidth
                            Layout.preferredHeight: btnHeight
                            // x: 152
                            // y: 13
                            text: qsTr("单位")
                            font.pixelSize: 18
                            background: Rectangle{
                                color: btnColor
                                    }
                            onClicked: {
                                unit.popup.open()
                            }
                        }
                        MyComboBox
                        {
                            id:unit
                            Layout.row:1
                            Layout.column:1
                            Layout.preferredWidth: btnWidth
                            Layout.preferredHeight: btnHeight
                            model:["ug","mg","g","kg","Mg","t","lb","dyne","kdyne","oz","TONNE"]
                            currentIndex: unit.find(mymodbus.unit)
                        }
                        Button
                        {
                            Layout.row:1
                            Layout.column:2
                            Layout.preferredWidth: btnWidth
                            Layout.preferredHeight: btnHeight
                            // x: 152
                            // y: 13
                            text: qsTr("轴数")
                            font.pixelSize: 18
                            background: Rectangle{
                                color: btnColor
                                    }
                            onClicked: {
                                unit.popup.open()
                            }
                        }
                        MyComboBox
                        {
                            id:axisCount
                            Layout.row:1
                            Layout.column:3
                            Layout.preferredWidth: btnWidth
                            Layout.preferredHeight: btnHeight
                            model:[1,2,3,4,5,6]
                            currentIndex:-1
                                //unit.find(mymodbus.unit)
                        }

                }

}

